package com.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.model.R;
import com.media.mapper.FavoriteMapper;
import com.media.model.Favorite;
import com.media.service.FavoriteService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 小何
 * @Description: TODO
 * @DateTime: 2023/10/30 16:49
 **/
@Service
public class FavoriteServiceImpl extends ServiceImpl<FavoriteMapper, Favorite> implements FavoriteService {
    @Override
    public R<List<Favorite>> listFavorite(Integer userId) {
        LambdaQueryWrapper<Favorite>qw=new LambdaQueryWrapper<>();
        qw.eq(Favorite::getUserId,userId);;
        List<Favorite> favoriteList = this.list(qw);
        return R.success(favoriteList);
    }

    @Override
    public R<String> cancelFavorite(String mediaId, Integer userId) {
        LambdaQueryWrapper<Favorite>qw=new LambdaQueryWrapper<>();
        qw.eq(Favorite::getUserId,userId).eq(Favorite::getMediaId,mediaId);
        this.remove(qw);
        return R.success("取消收藏成功");
    }

    @Override
    public R<Boolean> judgeFavorite(String mediaId, Integer userId) {
        LambdaQueryWrapper<Favorite>qw=new LambdaQueryWrapper<>();
        qw.eq(Favorite::getUserId,userId)
                .eq(Favorite::getMediaId,mediaId);
        Favorite one = this.getOne(qw);
        return R.success(one!=null);
    }
}
